<template>
  <div v-loading.lock="loading" class="base-content">
    <div class="basic-info">
      <el-form ref="queryForm" :inline="true" :model="queryForm">
        <el-form-item label="订单产品id" prop="orderProductId">
          <el-input
            v-model="queryForm.orderProductId"
            placeholder="订单产品id"
          />
        </el-form-item>
        <el-form-item label="订单id" prop="orderId">
          <el-input v-model="queryForm.orderId" placeholder="订单id" />
        </el-form-item>
        <el-form-item label="产品id" prop="productId">
          <el-input v-model="queryForm.productId" placeholder="产品id" />
        </el-form-item>
        <el-form-item label="产品编号" prop="productNum">
          <el-input v-model="queryForm.productNum" placeholder="产品编号" />
        </el-form-item>
        <el-form-item label="入库数量/出库数量" prop="productCount">
          <el-input
            v-model="queryForm.productCount"
            placeholder="入库数量/出库数量"
          />
        </el-form-item>
        <el-form-item label="库区" prop="storageAreaId">
          <el-input v-model="queryForm.storageAreaId" placeholder="库区" />
        </el-form-item>
        <el-form-item label="库区Name" prop="storageAreaName">
          <el-input
            v-model="queryForm.storageAreaName"
            placeholder="库区Name"
          />
        </el-form-item>
        <el-form-item label="库位" prop="storageSpaceId">
          <el-input v-model="queryForm.storageSpaceId" placeholder="库位" />
        </el-form-item>
        <el-form-item label="库位Name" prop="storageSpaceName">
          <el-input
            v-model="queryForm.storageSpaceName"
            placeholder="库位Name"
          />
        </el-form-item>
        <el-form-item label="证书编号" prop="certificateNum">
          <el-input v-model="queryForm.certificateNum" placeholder="证书编号" />
        </el-form-item>
        <el-form-item label="批次编号" prop="batchNum">
          <el-input v-model="queryForm.batchNum" placeholder="批次编号" />
        </el-form-item>
        <el-form-item label="供应商id" prop="supplierId">
          <el-input v-model="queryForm.supplierId" placeholder="供应商id" />
        </el-form-item>
        <el-form-item label="供应商Name" prop="supplierName">
          <el-input v-model="queryForm.supplierName" placeholder="供应商Name" />
        </el-form-item>
        <el-form-item label="生产日期" prop="dateManufacture">
          <el-input
            v-model="queryForm.dateManufacture"
            placeholder="生产日期"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onQuery">查询</el-button>
          <el-button @click="cancelForm">清空</el-button>
        </el-form-item>
      </el-form>

      <div class="base-content-operate">
        <el-button icon="el-icon-plus" type="primary" @click="onNew"
          >新增</el-button
        >
      </div>

      <el-table
        :data="list"
        element-loading-text="Loading"
        fit
        highlight-current-row
      >
        <el-table-column align="center" label="序号" width="50">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column label="订单产品id">
          <template slot-scope="scope">
            {{ scope.row.orderProductId }}
          </template>
        </el-table-column>
        <el-table-column label="订单id">
          <template slot-scope="scope">
            {{ scope.row.orderId }}
          </template>
        </el-table-column>
        <el-table-column label="产品id">
          <template slot-scope="scope">
            {{ scope.row.productId }}
          </template>
        </el-table-column>
        <el-table-column label="产品编号">
          <template slot-scope="scope">
            {{ scope.row.productNum }}
          </template>
        </el-table-column>
        <el-table-column label="入库数量/出库数量">
          <template slot-scope="scope">
            {{ scope.row.productCount }}
          </template>
        </el-table-column>
        <el-table-column label="库区">
          <template slot-scope="scope">
            {{ scope.row.storageAreaId }}
          </template>
        </el-table-column>
        <el-table-column label="库区Name">
          <template slot-scope="scope">
            {{ scope.row.storageAreaName }}
          </template>
        </el-table-column>
        <el-table-column label="库位">
          <template slot-scope="scope">
            {{ scope.row.storageSpaceId }}
          </template>
        </el-table-column>
        <el-table-column label="库位Name">
          <template slot-scope="scope">
            {{ scope.row.storageSpaceName }}
          </template>
        </el-table-column>
        <el-table-column label="证书编号">
          <template slot-scope="scope">
            {{ scope.row.certificateNum }}
          </template>
        </el-table-column>
        <el-table-column label="批次编号">
          <template slot-scope="scope">
            {{ scope.row.batchNum }}
          </template>
        </el-table-column>
        <el-table-column label="供应商id">
          <template slot-scope="scope">
            {{ scope.row.supplierId }}
          </template>
        </el-table-column>
        <el-table-column label="供应商Name">
          <template slot-scope="scope">
            {{ scope.row.supplierName }}
          </template>
        </el-table-column>
        <el-table-column label="生产日期">
          <template slot-scope="scope">
            {{ scope.row.dateManufacture }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <div class="base-table-operation">
              <el-link size="mini" type="primary" @click="handleEdit(scope.row)"
                >编辑</el-link
              >
              <el-link
                size="mini"
                type="danger"
                @click="handleDelete(scope.row)"
                >删除</el-link
              >
            </div>
          </template>
        </el-table-column>
      </el-table>

      <BasePagination
        :total="pagination.total"
        :current-page="pagination.pageIndex"
        :page-count="pagination.total"
        @changePage="changePage"
        @sizeChange="sizeChange"
      />
    </div>

    <MaterialOrderProductDetailsEdit
      ref="MaterialOrderProductDetailsEdit"
      :dialog-form-visible.sync="dialogFormVisible"
    />
  </div>
</template>

<script>
import { deleteRecord, getList } from "../../../api/Material/MaterialOrderProductDetails.js";
import MaterialOrderProductDetailsEdit from "./MaterialOrderProductDetailsEdit.vue";

export default {
  name: "MaterialOrderProductDetailsList",
  components: { MaterialOrderProductDetailsEdit },
  data() {
    return {
      loading: true,
      list: [],
      queryForm: {
        orderProductId: 0,
        orderId: 0,
        productId: 0,
        productNum: "",
        productCount: 0,
        storageAreaId: 0,
        storageAreaName: "",
        storageSpaceId: 0,
        storageSpaceName: "",
        certificateNum: "",
        batchNum: "",
        supplierId: 0,
        supplierName: "",
        dateManufacture: 0,
      },
      dialogFormVisible: false,
      pagination: {
        pageIndex: 1,
        pageSize: 10,
        total: 0,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    changePage(val) {
      this.pagination.pageIndex = val;
      this.getList();
    },
    sizeChange(val) {
      this.pagination.pageIndex = 1;
      this.pagination.pageSize = val;
      this.getList();
    },
    cancelForm() {
      this.$refs.queryForm.resetFields();
      this.pagination.pageIndex = 1;
      this.getList();
    },
    getList() {
      this.loading = true;
      getList(this.queryForm, this.pagination)
        .then((res) => {
          this.list = res.data.dataList ? res.data.dataList : [];
          this.pagination.total = res.data.total;
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
    onNew() {
      this.$refs.MaterialOrderProductDetailsEdit.formData = this.Helper.deepCopy(
        this.$refs.MaterialOrderProductDetailsEdit.initData
      );
      this.dialogFormVisible = true;
    },
    handleDelete(rowData) {
      this.Helper.deleteConfirm(() => {
        this.loading = true;
        deleteRecord({ id: rowData.id })
          .then((res) => {
            this.getList();
            this.loading = false;
          })
          .catch(() => {
            this.loading = false;
          });
      });
    },
    handleEdit(rowData) {
      this.$refs.MaterialOrderProductDetailsEdit.formData = rowData;
      this.dialogFormVisible = true;
    },
    onQuery() {
      this.getList();
    },
  },
};
</script>
